<template>
  <div>
    <router-tip></router-tip>
    <div class="orderTest-container" style="min-height: 600px;">
      <div class="content">
        <div class="blog-item">
          <div class="img">
            <img :src="blog.top_img" alt="" />
          </div>
          <div class="item">
            <div class="tip ">
              <div class="author">Mr.Lih</div>
              <div class="time line">{{ blog.create_time }}</div>
            </div>
            <div class="title">
              {{ blog.title }}
            </div>
            <div class="info mdimg" v-html="blog.content">
              <!-- <mavon-editor
                ref="md"
                v-model="blog.content"
                style="height: 600px"
                :editable="false"
                :toolbarsFlag="false"
                :subfield="false"
                default_open="preview"
              ></mavon-editor> -->

              <!-- {{ blog.content }} -->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { getBlogsDetail } from "@/api/getBlogs";
  import { mavonEditor } from "mavon-editor";

  export default {
    name: "Detail",
    components: { mavonEditor },
    data() {
      return {
        blog: [],
      };
    },
    created() {},
    mounted() {
      if (this.$route.params.id) {
        this.fetchData();
      } else {
        this.$router.push("/");
      }
      this.zoomImg();
    },
    computed: {},
    watch: {},
    methods: {
      async fetchData() {
        let { data } = await getBlogsDetail(this.$route.params);
        this.blog = data.data[0];
      },
      zoomImg() {
        this.$nextTick(() => {
          setTimeout(() => {
            let imgs = document.getElementsByTagName("img");
            imgs.forEach((item) => {
              console.log(item.currentSrc);
              item.addEventListener("click", (e) => {
                let ele = e.target;
                if (ele.id != "logo") {
                  // 打开图片遮罩大图显示
                  console.log("e", e.target.src);
                  window.open(e.target.src);
                }
              });
            });
          }, 1200);
        });
      },
    },
  };
</script>
<style lang="scss" scoped>
  .content {
    @include flex;
    flex-wrap: wrap;
    box-sizing: border-box;
    justify-content: space-between;
  }
  .blog-item {
    background-color: #12152f;
    box-sizing: border-box;
    width: 100%;
    border-radius: 10px;
    transition: 0.3s;
    margin-bottom: 20px;
  }
  .item {
    padding: 10px;
  }
  .blog-item:hover {
    .title {
      color: $hoverColor;
    }
  }
  .img {
    img {
      width: 100%;
      border-radius: 10px;
    }
  }
  .tip {
    @include flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 5px 20px;
    font-size: 18px;
  }
  .title {
    font-size: 20px;
    transition: 0.3s;
    text-align: center;
    margin: 15px 40px;
    font-size: 18px;
    line-height: 24px;
  }
  .info {
    margin: 15px 20px;
    color: #b0b0b2;
    font-size: 14px;
    line-height: 40px;
  }
  .more {
    color: $hoverColor;
    text-align: center;
    font-size: 14px;
  }
  .line {
    padding-left: 53px;
    &::after {
      width: 45px !important;
    }
  }
  @media screen and (max-width: 1024px) {
    .blog-item {
      width: 100%;

      .item {
        padding: 5px;
      }
    }
  }
  @media screen and (max-width: 725px) {
    .blog-item {
      width: 100%;
      .item {
        padding: 5px;
        margin-top: 10px;
      }
    }
  }
</style>
<style lang="scss">
  .mdimg {
    img {
      width: 100% !important;
      border-radius: 10px;
    }
  }
  .hljs {
    display: block;
    overflow-x: auto;
    padding: 0.5em;
    color: #35ace4;
    line-height: 25px;
    background: #12152f !important;
  }
  .hljs-keyword,
  .hljs-selector-tag,
  .hljs-subst {
    color: #9aa3f5;
  }
</style>
